#include	<sys/mman.h>
#include	<sys/stat.h>
#include	<sys/time.h>
#include	<stdint.h>
#include	<unistd.h>
#include	<fcntl.h>
#include	<cstdlib>
#include	<cstdio>
#include	<cstring>
using	namespace	std;
int	fd;
struct	stat	sb;
uint8_t	*data_ptr;
int	open_mmap(const	char	*F){
	fd=open(F,	O_RDONLY);	if(fd<0)	return	0;
	fstat(fd,	&sb);
	data_ptr=(uint8_t*)mmap(NULL,	sb.st_size,	PROT_READ,	MAP_SHARED,	fd,	0);
	if(data_ptr==MAP_FAILED)	return	0;
	return	1;
}
int	main(int	ac,	char	**av){
	unsigned	n=strlen(av[1]);
	for(int	k=2;	k<ac;	k++){
		open_mmap(av[k]);
		for(uint8_t	*p=data_ptr;(p=(uint8_t*)memmem(p,data_ptr+sb.st_size-p,av[1],n));){
			uint8_t	*q=p,	*t=p,	*s=data_ptr+sb.st_size-1;
			while(*q!='\n'&&q!=data_ptr)	q--;
			while(*t!='\n'&&q!=s)	t++;
			fwrite(q,t-q,1,stdout);
			p=t;
		}
		fputc('\n',stdout);
		munmap(data_ptr,sb.st_size);	close(fd);
	}
	return	0;
}
